package com.kefu.chat.smart.action;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.google.common.collect.Maps;
import com.kefu.chat.service.ChatAdminService;
import com.kefu.chat.service.ChatCacheService;
import com.kefu.chat.service.ChatSessionService;
import com.kefu.chat.smart.ChatConnectAction;
import com.kefu.chat.vo.ChatUserParam.UserConnectP;
import com.kefu.chat.vo.ChatUserParam.UserConnectR;
import com.kefu.common.trigger.Action;
import com.kefu.common.trigger.TriggerWrapper;
import com.kefu.common.trigger.model.ActionModel;
import com.kefu.common.trigger.model.DynamicModel;
import com.kefu.common.trigger.model.DynamicModel.SearchType;
import com.kefu.smart.special.QueueStrategy;

@Component
public class ChatConnectGroupAction implements ChatConnectAction{

	@Autowired
    private ChatCacheService chatCacheService;
    @Autowired
    private ChatAdminService chatAdminService;
    @Autowired
    private ChatSessionService chatSessionService;
    
	    
	@Override
	public boolean doAction(TriggerWrapper<UserConnectP, UserConnectR> wrapper, Action action) {
		UserConnectP param=new UserConnectP();
		param.setUserId(wrapper.getNewObj().getUserId());
		param.setAdminId(wrapper.getNewObj().getAdminId());
		param.setGroupId(action.getSubAction());
		
		boolean queue=QueueStrategy.Queue.name().equals(action.getOperatorValue());
		param.setQueue(queue);
		wrapper.getActionObj().getActions().add(param);
		return false;

	}

	@Override
	public ActionModel getActionModel() {
		Map<String,String> groupSearch=Maps.newHashMap();
		 groupSearch.put("groupType", "0");
		 DynamicModel<ActionModel> dynamicModel= DynamicModel.<ActionModel>builder()
			.url("smart/trigger/group/list/QueueStrategy")
			.code("code")
			.name("name")
			.searchType(SearchType.List)
			.params(groupSearch)
			.build();
		 
		return ActionModel.builder()
				.code(getCode())
				.name(getMessageName())
				.dynamicModel(dynamicModel)
				.build();
	}

	@Override
	public String getCode() {
		return "group_id";
	}

	@Override
	public String getName() {
		return "分配到技能组";
	}

}
